package com.example.swim.Service;

import com.example.swim.Dao.NewsDao;
import com.example.swim.Pojo.News;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author LiYa
 * @create 2022-11-26 14:38
 */
@Transactional
@Service
public class NewsService {
    @Autowired
    NewsDao newsDao;

    @Cacheable(value = "news",key = "'Allnews'")
    public List<News> getAll(){
        return newsDao.selectList(null);
    }

    @CacheEvict(value = "news",key = "'Allnews'")
    public List<News> update(News news){
        newsDao.updateById(news);
        return newsDao.selectList(null);
    }

    @CacheEvict(value = "news",allEntries = true)
    public int del(int id){
        return newsDao.deleteById(id);
    }

    @CachePut(value="news",key = "'Allnews'")
    public List<News> insert(News news){
        newsDao.insert(news);
        return newsDao.selectList(null);
    }
}
